package com.example.demo.dao;

import com.example.demo.model.Articleinfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ArticleMapper {

    /**
     * 根据用户id获取文章列表
     * @return
     */
    @Select("select * from articleinfo where uid = #{uid} order by id desc")
    List<Articleinfo> getListByUid(@Param("uid")int uid);

//    @Select("select * from articleinfo where id = #{id} and uid = #{uid}")
//    int getArtByAid(@Param("id")Integer aid,int uid);
    @Select("select * from articleinfo where id = #{aid} and uid = #{uid}")
    Articleinfo getArticleByUid(@Param("aid")int aid ,
                                @Param("uid")int uid);


    @Select("select * from articleinfo where id = #{aid}")
    Articleinfo getArtById(@Param("aid")Integer aid);

    @Update("update articleinfo set title = #{title} , content = #{content} ,updatetime = #{updatetime}where id = #{id} and uid = #{uid}")
    int update_sub(Articleinfo articleinfo) ;
    @Delete("delete from articleinfo where id = #{aid} and uid = #{uid}")
    int del(@Param("aid")Integer aid , int uid);

    @Insert("insert into articleinfo (title,content,uid) values (#{title},#{content},#{uid})")
    int add(Articleinfo articleinfo);

    @Select("select count(*) from articleinfo where uid = #{uid}")
    int getArtCOuntByUId (@Param("uid")int uid);

    @Update("update articleinfo set rcount=rcount + 1 where id = #{aid}")
    int updateRcount(@Param("aid") Integer aid) ;

    @Select("select * from articleinfo order by id desc  limit #{psize} offset #{offset}")
    List<Articleinfo> getListByPage(@Param("psize") int psize,
                              @Param("offset") int offset);

    @Select("select count(*) from articleinfo")
    int getArtCount ();

}
